package com.algorithm;

public class Candy {
    static int jump(int[] nums) {
        int length = nums.length;
        int end = 0;
        int maxPosition = 0;
        int steps = 0;
        for (int i = 0; i < length - 1; i++) {
            maxPosition = Math.max(maxPosition, i + nums[i]);
            if (i == end) {
                end = maxPosition;
                steps++;
            }
            System.out.println(end+",maxPosition="+maxPosition);
        }
        return steps;
    }

    public static void main(String[] args) {
        //System.out.println(jump(new int[]{2,3,1,2,4,2,3}));
        System.out.println(jump(new int[]{2,0,0,1,4}));
    }
}
